<template>
  <div class="demo">
    <h2>学校名称：{{ name }}</h2>
    <h2>学校地址：{{ address }}</h2>
  </div>
</template>

<script>
import pubsub from "pubsub-js";
export default {
  name: "SchoolSchool",
  props: ["getSchoolName"],
  data() {
    return {
      name: "CQQQQQQ",
      address: "SD",
    };
  },
  mounted() {
    // console.log('School',this)
    // this.$bus.$on("hello", (data) => {
    //   console.log("School的on事件触发",data);
    // });
    this.pubId = pubsub.subscribe("hello", (msgName, data) => {
      console.log(this); //undefined因为不是Vue的技术
      // console.log("触发hello", msgName, data);
    });
  },
  beforeDestroy() {
    // this.$bus.$off("hello");
    pubsub.unsubscribe(this.pubId);
  },
};
</script>

<style scoped>
/* 
scoped解决冲突
app不适用：app的样式会是很多组件使用的样式
*/
.demo {
  background-color: aliceblue;
  padding: 5px;
}
</style>

